package com.henu.xyh;

import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import com.henu.R;

import com.henu.tanhang.ApplicationHenu;

import com.henu.xyh.fragmentofXYH.Campus;
import com.henu.xyh.fragmentofXYH.Home;
import com.henu.xyh.fragmentofXYH.Mine;


import cn.bmob.v3.Bmob;



public class MainActivity extends AppCompatActivity {

    RadioGroup group;
    Fragment f1;
    Fragment f2;
    Fragment f3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        ApplicationHenu.getInstance().addActivity(this);
        Bmob.initialize(this, "a24db0fac16b375a97072b85080ea20f");
        group= (RadioGroup) findViewById(R.id.main_group);
        FragmentManager fm=getSupportFragmentManager();//获取对象
        FragmentTransaction ft=fm.beginTransaction();
        f1=new Home();
        f2=new Campus();
        f3=new Mine();

        ft.add(R.id.fragment,f1);
        ft.commit();

        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                FragmentManager fm=getSupportFragmentManager();//获取对象
                FragmentTransaction ft=fm.beginTransaction();
                if(i==R.id.btn_fist){
                    ft.replace(R.id.fragment,f1);
                }
                else if(i==R.id.btn_campus){
                    ft.replace(R.id.fragment,f2);
                }
                else {
                    ft.replace(R.id.fragment,f3);
                }
                ft.commit();
            }
        });
    }

}
